package com.icoopoo.flux.webflux;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class GreetingRouter {

  @Bean
  public RouterFunction<ServerResponse> route(GreetingHandler t) {

    return RouterFunctions
      .route(RequestPredicates.GET("/hello").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), t::hello);
  }

  @Bean
  public RouterFunction<ServerResponse> route2(GreetingHandler t) {
    return RouterFunctions
            .route(RequestPredicates.POST("/hello2").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), t::hello2);
  }
}